(ꞌRest Proxy in Storeꞌ)   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 90

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 90
rs 8.5454
cc 1
nc 1
nop 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
B restproxystore.spec.js ➔ ... ➔ it(ꞌshould add new entityꞌ) 0 29 1
B restproxystore.spec.js ➔ ... ➔ it(ꞌshould load all the entityꞌ) 0 25 1
B restproxystore.spec.js ➔ ... ➔ it(ꞌshould remove all entityꞌ) 0 25 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
describe('Rest Proxy in Model', function() {
2
    it('should save entity', function() {
3
        var owner = Ext.create('Test.TestBundle.Entity.CarOwner', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
4
            name: 'James'
5
        });
6
        var runned = false;
7
        runs(function() {
8
            owner.save({
9
                callback: function(record, operation, success) {
0 ignored issues
show
Unused Code introduced by
The parameter operation is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter success is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
10
                    Test.TestBundle.Entity.CarOwner.load(record.getId(), {
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
11
                        callback: function(record) {
12
                            owner = record;
13
                            runned = true;
14
                        }
15
                    });
16
                }
17
            });
18
        });
19
        waitsFor(function() {
20
            return runned;
21
        });
22
        runs(function() {
23
            expect(owner.get('name')).toBe('James');
24
        });
25
    });
26
    it('should save existing entity with new hasMany association', function() {
27
        var owner = Ext.create('Test.TestBundle.Entity.CarOwner', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
28
            name: 'James'
29
        });
30
        var runned = false;
31
        runs(function() {
32
            owner.save({
33
                callback: function(record, operation, success) {
0 ignored issues
show
Unused Code introduced by
The parameter record is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter success is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter operation is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
34
                    owner.cars().add({
35
                        name: 'Ford',
36
                        plateNumber: 'AA1234',
37
                        password: 'xx'
38
                    }, {
39
                        name: 'BMW',
40
                        plateNumber: 'ASF87654',
41
                        password: 'xx'
42
                    });
43
                    owner.cars().sync({
44
                        callback: function() {
45
                            Test.TestBundle.Entity.CarOwner.load(owner.getId(), {
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
                                callback: function(record) {
47
                                    owner = record;
48
                                    runned = true;
49
                                }
50
                            });
51
                        }
52
                    });
53
                }
54
            });
55
        });
56
        waitsFor(function() {
57
            return runned;
58
        });
59
        runs(function() {
60
            expect(owner).not.toBeNull();
61
            expect(owner.cars().count()).toBe(2);
62
            expect(owner.cars().first().get('name')).toBe('Ford');
63
            expect(owner.cars().first().getCarOwner()).toBe(owner);
64
        });
65
    });
66
    it('should save existing entity with existing hasMany association', function() {
67
        var owner = Ext.create('Test.TestBundle.Entity.CarOwner', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
68
            name: 'James'
69
        });
70
        var runned = false;
71
        runs(function() {
72
            owner.save({
73
                callback: function(record, operation, success) {
0 ignored issues
show
Unused Code introduced by
The parameter success is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter record is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter operation is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
74
                    var car = Ext.create('Test.TestBundle.Entity.Car', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
75
                        name: 'Ford',
76
                        plateNumber: 'AA1234',
77
                        password: 'xx'
78
                    });
79
                    car.save({
80
                        callback: function(record) {
81
                            owner.cars().add(record);
82
                            owner.cars().sync({
83
                                callback: function() {
84
                                    owner.cars().first().getCarOwner({
85
                                        callback: function() {
86
                                            runned = true;
87
                                        }
88
                                    });
89
                                }
90
                            });
91
                        }
92
                    });
93
                }
94
            });
95
        });
96
        waitsFor(function() {
97
            return runned;
98
        });
99
        runs(function() {
100
            expect(owner).not.toBeNull();
101
            expect(owner.cars().count()).toBe(1);
102
            expect(owner.cars().first().get('name')).toBe('Ford');
103
            expect(owner.cars().first().getCarOwner().getData()).toEqual(owner.getData());
104
        });
105
    });
106
    it('should save existing entity with existing belongTo association', function() {
107
        var car = Ext.create('Test.TestBundle.Entity.Car', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
108
            name: 'Ford',
109
            plateNumber: 'AA1234',
110
            password: 'xx'
111
        });
112
        var runned = false;
113
        var car_owner_id;
114
        runs(function() {
115
            car.save({
116
                callback: function(record) {
0 ignored issues
show
Unused Code introduced by
The parameter record is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
117
                    var owner = Ext.create('Test.TestBundle.Entity.CarOwner', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
118
                        name: 'James Y'
119
                    });
120
                    owner.save({
121
                        callback: function(record) {
122
                            car.setCarOwner(record, {
123
                                callback: function() {
124
                                    runned = true;
125
                                    car_owner_id = car.get('car_owner_id');
126
                                }
127
                            });
128
                        }
129
                    });
130
                }
131
            });
132
        });
133
        waitsFor(function() {
134
            return runned;
135
        });
136
137
        // Reload Car entity from REST proxy. Car_owner_id should still be there.
138
        var runned1 = false;
139
        runs(function() {
140
            Test.TestBundle.Entity.Car.load(car.get('id'), {
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
141
                callback: function(record) {
142
                    record.set('name', 'Audi');
143
144
                    // Save and reload again. If car_owner_id was not there the belongsTo association is destroyed.
145
                    record.save({
146
                        callback: function(record) {
0 ignored issues
show
Unused Code introduced by
The parameter record is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
147
                            Test.TestBundle.Entity.Car.load(car.get('id'), {
0 ignored issues
show
Bug introduced by
The variable Test seems to be never declared. If this is a global, consider adding a /** global: Test */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
148
                                callback: function(record) {
149
                                    car = record;
150
                                    runned1 = true;
151
                                }
152
                            });
153
                        }
154
                    });
155
                }
156
            });
157
        });
158
        waitsFor(function() {
159
            return runned1;
160
        });
161
162
        runs(function() {
163
            expect(car.getCarOwner()).not.toBeNull();
164
            expect(car.get('car_owner_id')).toBe(car_owner_id);
165
            expect(car.getCarOwner().get('name')).toBe('James Y');
166
            expect(car.get('name')).toBe('Audi');
167
        });
168
    });
169
    it('should update entity', function() {
170
        var car = Ext.create('Test.TestBundle.Entity.Car', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
171
            name: 'Ford',
172
            plateNumber: 'AA1234',
173
            password: 'xx'
174
        });
175
        var originalId;
176
        var runned = false;
177
        runs(function() {
178
            car.save({
179
                callback: function(record) {
180
                    originalId = record.getId();
181
                    record.set('name', 'BMW');
182
                    record.save({
183
                        callback: function(record) {
184
                            car = record;
185
                            runned = true;
186
                        }
187
                    })
188
                }
189
            })
190
        });
191
        waitsFor(function() {
192
            return runned;
193
        });
194
        runs(function() {
195
            expect(originalId).toBe(car.getId());
196
            expect(car.get('name')).toBe('BMW');
197
        });
198
    })
199
});
200
describe('Rest Proxy in Store', function() {
201
    var store = Ext.create('Ext.data.Store', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
202
        model: 'Test.TestBundle.Entity.Car',
203
        autoLoad: false,
204
        proxy: {
205
            type: 'rest',
206
            url: '/mycars',
207
            format: 'json'
208
        }
209
    });
210
    it('should load all the entity', function() {
211
        var runned = false;
212
        runs(function() {
213
            var car = Ext.create('Test.TestBundle.Entity.Car', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
214
                name: 'Ford',
215
                plateNumber: 'AA1234',
216
                password: 'xx'
217
            });
218
            car.save({
219
                callback: function() {
220
                    store.load({
221
                        callback: function() {
222
                            runned = true;
223
                        }
224
                    });
225
                }
226
            });
227
        });
228
        waitsFor(function() {
229
            return runned;
230
        });
231
        runs(function() {
232
            expect(store.count()).toBeGreaterThan(0);
233
        })
234
    });
235
    it('should remove all entity', function () {
236
        var runned = false;
237
        runs(function () {
238
            store.load({
239
                callback: function() {
240
                    store.removeAll();
241
                    store.sync({
242
                        callback: function() {
243
                            store.load({
244
                                callback: function() {
245
                                    runned = true;
246
                                }
247
                            })
248
                        }
249
                    })
250
                }
251
            });
252
        });
253
        waitsFor(function () {
254
            return runned;
255
        });
256
        runs(function () {
257
            expect(store.count()).toBe(0);
258
        });
259
    });
260
    it('should add new entity', function () {
261
        var runned = false;
262
        runs(function () {
263
            store.add([
264
                {
265
                    name: 'Ford',
266
                    plateNumber: 'AA1234',
267
                    password: 'xx'
268
                },
269
                {
270
                    name: 'BMW',
271
                    plateNumber: 'ZZ54',
272
                    password: 'xx'
273
                }
274
            ]);
275
            store.sync({
276
                callback: function() {
277
                    runned = true;
278
                }
279
            });
280
        });
281
        waitsFor(function () {
282
            return runned;
283
        });
284
        runs(function () {
285
            expect(store.count()).toBe(2);
286
            expect(store.getNewRecords().length).toBe(0);
287
        });
288
    });
289
});